#ifndef UEDIT
#define UEDIT
#include "../stdafx.h"
#include "UControl.h"
#include "../UGLFont.h"
#include "../UCallBack.h"
#include "../UVector.h"

class TEdit: public TControl
{
private:
	int Position;
	int CursorTimer;
	int SelPos;
	size_t CharIndexAtX(int X);
	std::string Text;
	TGLFontObj* FontObj;
	
	SDLKey KeyPressed;
	int FrameCountLastPressed;
	int HorScroll;

	int Length; //Distance from first char to cursor in pixels
	int Length2;//Distance from first char to Seletion

	void ReCalculateAll();
	void DeleteSelection();
	void CopySelection();
	int LastX;
	bool MState;
public:
	TVector textcolor; //defines the textcolors (r,g,b), in the range [0..1]
	TGLFontRef Font;
	void SetText(std::string text);
	std::string GetText();
	TEdit(TRectangle rect);
	virtual void Draw();
	virtual void MouseDown	(int X, int Y, uint8 button);
	virtual void MouseUp	(int X, int Y, uint8 button);
	virtual void MouseMove	(int X, int Y, int mstate);
	virtual void KeyDown	(SDL_KeyboardEvent* Key);
	virtual void KeyUp		(SDL_KeyboardEvent* Key);

	function<void()> onChange;
	function<void()> onEnter;

	bool clearOnEnter;
};

#endif
